package org.flashIso.engine.library.objects
{
	import org.flashIso.engine.core.ILibrary;

	public class LObjectBase extends LBase
	{
		
		protected var _deltaX : int = 0;
		protected var _deltaY : int = 0;
		protected var _deltaZ : int = 0;
		
		protected var _fillColor : uint = 0x999999;
		protected var _fillAlpha : Number = 0.5;
		protected var _lineThickness : uint = 1;
		protected var _lineColor : uint = 0;
		protected var _lineAlpha : Number = 1;
		protected var _useImageFramesWhenRotating : Boolean = true;
		protected var _drawShape : Boolean = true;

		protected var _image:LImage;

		protected var _imageX : Number = 0;
		protected var _imageY : Number = 0;
		
		protected var _imageScaleX : Number = 1;
		protected var _imageScaleY : Number = 1;
		
		protected var _imageRotation : Number = 0;
		protected var _imageAlpha : Number = 1;

		protected var _xSize : uint = 50;
		protected var _ySize : uint = 50;
		protected var _zSize : uint = 50;
		
		protected var _hitAreaType : String = "none";

		
		public function get deltaX() : int {
			return _deltaX;
		}
		public function set deltaX(value : int) : void {
			if(_deltaX != value){
				_deltaX = value;
				triggerValidation();
			}
		}
		
		public function get deltaY() : int {
			return _deltaY;
		}
		public function set deltaY(value : int) : void {
			if(_deltaY != value){
				_deltaY = value;
				triggerValidation();
			}
		}
		
		public function get deltaZ() : int {
			return _deltaZ;
		}
		public function set deltaZ(value : int) : void {
			if(_deltaZ != value){
				_deltaZ = value;
				triggerValidation();
			}
		}
		
		public function get fillColor() : uint {
			return _fillColor;
		}
		public function set fillColor(value : uint) : void {
			if(_fillColor != value){
				_fillColor = value;
				triggerValidation();
			}
		}
		
		public function get fillAlpha() : Number {
			return _fillAlpha;
		}
		public function set fillAlpha(value : Number) : void {
			if(_fillAlpha != value){
				_fillAlpha = value;
				triggerValidation();
			}
		}
		
		public function get lineThickness() : uint {
			return _lineThickness;
		}
		public function set lineThickness(value : uint) : void {
			if(_lineThickness != value){
				_lineThickness = value;
				triggerValidation();
			}
		}
		
		public function get lineColor() : uint {
			return _lineColor;
		}
		public function set lineColor(value : uint) : void {
			if(_lineColor != value){
				_lineColor = value;
				triggerValidation();
			}
		}
		
		public function get lineAlpha() : Number {
			return _lineAlpha;
		}
		public function set lineAlpha(value : Number) : void {
			if(_lineAlpha != value){
				_lineAlpha = value;
				triggerValidation();
			}
		}
		
		public function get useImageFramesWhenRotating() : Boolean {
			return _useImageFramesWhenRotating;
		}
		public function set useImageFramesWhenRotating(value : Boolean) : void {
			if(_useImageFramesWhenRotating != value){
				_useImageFramesWhenRotating = value;
				triggerValidation();
			}
		}
		public function get drawShape() : Boolean {
			return _drawShape;
		}
		public function set drawShape(value : Boolean) : void {
			if(_drawShape != value){
				_drawShape = value;
				triggerValidation();
			}
		}
		
		public function get image() : LImage {
			return _image;
		}
		public function set image(value : LImage) : void {
			if(_image != value){
				_image = value;
				triggerValidation();
			}
		}
		//////////////////
		public function get imageX() : Number {
			return _imageX;
		}
		public function set imageX(value : Number) : void {
			if(_imageX != value){
				_imageX = value;
				triggerValidation();
			}
		}
		
		public function get imageY() : Number {
			return _imageY;
		}
		public function set imageY(value : Number) : void {
			if(_imageY != value){
				_imageY = value;
				triggerValidation();
			}
		}
		//////////////////
		public function get imageScaleX() : Number {
			return _imageScaleX;
		}
		public function set imageScaleX(value : Number) : void {
			if(_imageScaleX != value){
				_imageScaleX = value;
				triggerValidation();
			}
		}
		
		public function get imageScaleY() : Number {
			return _imageScaleY;
		}
		public function set imageScaleY(value : Number) : void {
			if(_imageScaleY != value){
				_imageScaleY = value;
				triggerValidation();
			}
		}
		
		public function get imageRotation() : Number {
			return _imageRotation;
		}
		public function set imageRotation(value : Number) : void {
			if(_imageRotation != value){
				_imageRotation = value;
				triggerValidation();
			}
		}
		
		public function get imageAlpha() : Number {
			return _imageAlpha;
		}
		public function set imageAlpha(value : Number) : void {
			if(_imageAlpha != value){
				_imageAlpha = value;
				triggerValidation();
			}
		}
		
		public function get xSize() : uint {
			return _xSize;
		}
		public function set xSize(value : uint) : void {
			if (_xSize != value){
				_xSize = value;
				triggerValidation();
			}
		}
		
		public function get ySize() : uint {
			return _ySize;
		}
		public function set ySize(value : uint) : void {
			if(_ySize != value){
				_ySize = value;
				triggerValidation();
			}
		}
		
		public function get zSize() : uint {
			return _zSize;
		}
		public function set zSize(value : uint) : void {
			if(_zSize != value){
				_zSize = value;
				triggerValidation();
			}
		}

		public function get hitAreaType() : String {
			return _hitAreaType;
		}
		public function set hitAreaType(value : String) : void {
			if(_hitAreaType != value){
				_hitAreaType = value;
				triggerValidation();
			}
		}
		
		override public function toXML() : XML {
			var xml:XML = super.toXML();
			
			xml.@deltaX = deltaX;
			xml.@deltaY = deltaY;
			xml.@deltaZ = deltaZ;

			xml.@fillColor = fillColor;
			xml.@fillAlpha = fillAlpha;
			xml.@lineThickness = lineThickness;
			xml.@lineColor = lineColor;
			xml.@lineAlpha = lineAlpha;
			
			xml.@useImageFramesWhenRotating = useImageFramesWhenRotating;
			xml.@drawShape = drawShape;
			if (image != null) {
				xml.@imageID = image.id;
			}
			xml.@imageX = imageX;
			xml.@imageY = imageY;
			xml.@imageScaleX = imageScaleX;
			xml.@imageScaleY = imageScaleY;

			xml.@imageRotation = imageRotation
			xml.@imageAlpha = imageAlpha;
			xml.@xSize = xSize;
			xml.@ySize = ySize;
			xml.@zSize = zSize;

			xml.@hitAreaType = hitAreaType;
			return xml;
		}
		
		override public function fromXML(xml:XML, library:ILibrary = null) : void {
			super.fromXML(xml, library);
			deltaX = parseFloat(xml.@deltaX);
			deltaY = parseFloat(xml.@deltaY);
			deltaZ = parseFloat(xml.@deltaZ);

			fillColor = parseFloat(xml.@fillColor);
			fillAlpha = parseFloat(xml.@fillAlpha);
			lineThickness = parseFloat(xml.@lineThickness);
			lineColor = parseFloat(xml.@lineColor);
			lineAlpha = parseFloat(xml.@lineAlpha);
			
			useImageFramesWhenRotating = (xml.@useImageFramesWhenRotating + "").toLowerCase() == "true";
			drawShape = (xml.@drawShape + "").toLowerCase() == "true";
			if (library != null){
				image = library.getLImageByID(xml.@imageID + "");
			}

			imageX = parseFloat(xml.@imageX);
			imageY = parseFloat(xml.@imageY);
			imageScaleX = parseFloat(xml.@imageScaleX);
			imageScaleY = parseFloat(xml.@imageScaleY);
			
			imageRotation = parseFloat(xml.@imageRotation);
			imageAlpha = parseFloat(xml.@imageAlpha);
			xSize = parseFloat(xml.@xSize);
			ySize = parseFloat(xml.@ySize);
			zSize = parseFloat(xml.@zSize);
			hitAreaType = (xml.@hitAreaType + "");

		}

	}
}